// shopPages/enterprise/enterprise.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isCreate: 0,
    staffList: [],
    hehuoList: [],
    companyname: '',
    company_logo: '',
    tabarr: ['员工', '合伙人'],
    curren: 0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  staffxq(e) {
    console.log(e)
    var staff_info = {};
    staff_info.staffname = e.currentTarget.dataset.staffname;
    staff_info.staffpic = e.currentTarget.dataset.staffpic;
    staff_info.staffid = e.currentTarget.dataset.staffid;
    wx.navigateTo({
      url: '/shopPages/staffxq/staffxq?staff=' + encodeURIComponent(JSON.stringify(staff_info))
    })
  },
  bindtab(e) {
    var curren = e.currentTarget.id
    this.setData({
      curren: curren
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.globalData.bossradar + '/api/1.0/getMyCompany',
      data: {
        bossId: app.globalData.userInfo.id,
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        // console.log(res.data)
        if (res.data.data.bossId != undefined && res.data.data.bossId.length != 0) {
          that.setData({
            isCreate: 1,
            companyname: res.data.data.companyName,
            company_logo: res.data.data.companyIcon
          });
          that.getStaff();
        } else {
          that.setData({
            isCreate: 0
          });
        }
      }
    })
    that.gethehuo()
  },
  gethehuo() {
    var that = this;
    wx.request({
      url: app.globalData.bossradar + '/api/1.0/getPartner',
      data: {
        bossId: app.globalData.userInfo.id,
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        that.setData({
          hehuoList: res.data.data
        })
      }
    })

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },

  createCompany: function () {
    wx.navigateTo({
      url: '/shopPages/Apply/Apply',
    })
  },
  addStaff: function () {
    wx.navigateTo({
      url: '/shopPages/addstaff/addstaff',
    })
  },
  addhehuo: function () {
    wx.navigateTo({
      url: '/shopPages/addstaff/addstaff?type=1',
    })
  },
  staffChange(e) {
    wx.navigateTo({
      url: '/shopPages/delstaff/delstaff?staffName=' + encodeURIComponent(this.data.staffList[e.currentTarget.id].staffName) + '&staffid=' + this.data.staffList[e.currentTarget.id].staffId + '&position=' + this.data.staffList[e.currentTarget.id].staffPosition + "&imgsrc=" + encodeURIComponent(e.currentTarget.dataset.staffpic)
    })
  },
  partnerChange(e) {
    wx.navigateTo({
      url: '/shopPages/delstaff/delstaff?staffName=' + encodeURIComponent(this.data.hehuoList[e.currentTarget.id].staffName) + '&staffid=' + this.data.hehuoList[e.currentTarget.id].staffId + '&position=' + this.data.hehuoList[e.currentTarget.id].staffPosition + '&type=1',
    })
  },
  getStaff: function () {
    var that = this;
    wx.request({
      url: app.globalData.bossradar + '/api/1.0/getStaff',
      data: {
        bossId: app.globalData.userInfo.id,
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        that.setData({
          staffList: res.data.data
        })
      }
    })
  }
})